Public Class ExcelDataSource
    Inherits DataSource

    Public Overrides ReadOnly Property Type As String
        Get
            Return "Excel"
        End Get
    End Property

    Public Property FileName As String

    Public Property DataSourceType As SourceType

    Public Overrides Function Query(ByVal txt As String) As DataTable
        Dim oleconstr = New OleDb.OleDbConnectionStringBuilder()
        oleconstr.Provider = "Microsoft.ACE.OLEDB.12.0"
        oleconstr.DataSource = FileName
        oleconstr.Add("Extended Properties", "Excel 12.0 Xml;HDR=YES")

        Dim adapter = New OleDb.OleDbDataAdapter(txt, oleconstr.ConnectionString)

        Dim data As New DataTable
        adapter.Fill(data)

        Return data
    End Function

    Public Enum SourceType
        Sheet
        NamedRange
        Table
        ListObject
    End Enum

    Public Overrides Sub Save(container As XElement)
        MyBase.Save(container)

        container.@FileName = Me.FileName
        container.@DataSourceType = Me.DataSourceType

    End Sub
End Class
